package com.paic.mhis.hcpms.common.community.web.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alibaba.fastjson.JSONObject;
import com.paic.mhis.common.util.HttpProcessUtil;
import com.paic.mhis.core.auth.biz.service.UserDetails;
import com.paic.mhis.hcpms.common.community.biz.service.BaseService;
import com.paic.pafa.appclient.annotation.BizServicesProxy;
import com.paic.pafa.web.BaseRest;

@Controller
public class BaseController extends BaseRest {

	@BizServicesProxy(beanName = "baseService")
	private BaseService baseService;

	/**
	 * 根据codetype查询基表对应的数据
	 */
	@RequestMapping(value = "/common/code", method = RequestMethod.POST)
	public Map<String, Object> getCodeType(HttpServletRequest request) throws Exception {
		Map<String, Object> result = null;
		try {
			String codeType = request.getParameter("codeType");
			String orgTypeCode = request.getParameter("orgTypeCode");
			String codeNo = request.getParameter("codeNo");
			String regionType = request.getParameter("regionType");
			String departmentType = request.getParameter("departmentType");
			// String str = HttpProcessUtil.readRequestBody(request);
			UserDetails user = (UserDetails) request.getSession().getAttribute("user");
			// 协议模块：统筹区域
			// String currentUser = request.getRemoteUser();

			JSONObject transferJson = new JSONObject();
			transferJson.put("currentUser", user.getUsername());
			transferJson.put("codeNo", codeNo);
			transferJson.put("areaCode", user.getAreaCode());
			transferJson.put("codeType", codeType);
			transferJson.put("orgTypeCode", orgTypeCode);
			transferJson.put("regionType", regionType);
			transferJson.put("departmentType", departmentType);
			result = baseService.getCode(transferJson);
		} catch (Exception e) {
			result = HttpProcessUtil.processException(e);
		}
		return result;
	}

}
